<template>
    <el-form :model="ruleForm" :rules="rules" label-width="130px" ref="ruleFormRef">
        <!-- 基本信息 -->
        <div class="bg-white mt-[10px]">
            <BaseHead>基本信息</BaseHead>
            <div class="p-[10px]">

                <el-row :gutter="20">
                    <el-col :span="24">
                        <el-form-item label="名称" prop="name">
                            <el-input placeholder="请输入名称" v-model="ruleForm.name" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="发表/出版时间" prop="publishDate">
                            <el-date-picker v-model="ruleForm.publishDate" ref="publishDateRef" type="date"
                                format="YYYY/MM/DD" value-format="YYYY-MM-DD" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="发表/刊物论文集" prop="magazineName">
                            <!-- <el-input placeholder="请输入发表/刊物论文集" v-model="ruleForm.magazineName" clearable></el-input> -->
                            <el-autocomplete placeholder="请输入发表/刊物论文集" ref="magazineNameRef"
                                v-model="ruleForm.magazineName" @focus="focusMagazineName"
                                :fetch-suggestions="querySearch" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="论文类型" prop="modeId">
                            <el-radio-group v-model="ruleForm.modeId"
                                @change="ruleForm.paperLevelIdList = [], ruleForm.embodyTypeIdList = []">
                                <el-radio v-for="item in lwlx" :key="item.code" :value="item.code" size="large">{{
        item.name }}</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="所属单位" prop="unitId">
                            <el-select v-model="ruleForm.unitId"
                                :disabled="(tableData && tableData[0].disable) || Cookies.get('role-key') == 'biz_kyry'"
                                placeholder="请选择所属单位" clearable>
                                <el-option v-for="item in zcgsdwList" :key="item.codeColumn" :label="item.valueColumn"
                                    :value="item.codeColumn" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="刊物级别" prop="paperLevelIdList">
                            <el-checkbox-group v-if="ruleForm.modeId == '1'" v-model="ruleForm.paperLevelIdList">
                                <el-checkbox v-for="item in qklwList" :key="item.code" :label="item.name"
                                    :value="item.code" />
                            </el-checkbox-group>
                            <el-checkbox-group v-if="ruleForm.modeId == '2'" v-model="ruleForm.paperLevelIdList">
                                <el-checkbox v-for="item in hylwList" :key="item.code" :label="item.name"
                                    :value="item.code" />
                            </el-checkbox-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="收录类别">
                            <el-checkbox-group v-if="ruleForm.modeId == '1'" v-model="ruleForm.embodyTypeIdList">
                                <el-checkbox v-for="item in qklwslList" :key="item.code" :label="item.name"
                                    :value="item.code" />
                            </el-checkbox-group>
                            <el-checkbox-group v-if="ruleForm.modeId == '2'" v-model="ruleForm.embodyTypeIdList">
                                <el-checkbox v-for="item in hylwslList" :key="item.code" :label="item.name"
                                    :value="item.code" />
                            </el-checkbox-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="ruleForm.modeId == '2'">
                        <el-form-item label="会议名称" prop="meetingName">
                            <el-input v-model="ruleForm.meetingName" type="number" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="ruleForm.modeId == '2'">
                        <el-form-item label="会议地址" prop="meetingAddress">
                            <el-input v-model="ruleForm.meetingAddress" type="number" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="ruleForm.embodyTypeIdList.includes('300601')">
                        <el-form-item label="SCI论文分区" prop="sciPartition">
                            <el-select v-model="ruleForm.sciPartition" clearable>
                                <el-option label="一区" value="1" />
                                <el-option label="二区" value="2" />
                                <el-option label="三区" value="3" />
                                <el-option label="四区" value="4" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="ruleForm.embodyTypeIdList.includes('300601')">
                        <el-form-item label="影响因子">
                            <el-input v-model="ruleForm.factor" type="number" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="教育部统计归属" prop="subjectClassId">
                            <el-radio-group v-model="ruleForm.subjectClassId" @change="changeSub">
                                <el-radio value="2" size="large">科技类</el-radio>
                                <el-radio value="1" size="large">社科类</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="一级学科" prop="subjectId">
                            <el-select v-model="ruleForm.subjectId" v-if="ruleForm.subjectClassId == '2'"
                                placeholder="请选择一级学科" clearable>
                                <el-option v-for=" item  in  kjxkflList " :key="item.id" :label="item.label"
                                    :value="item.id" />
                            </el-select>
                            <el-select v-model="ruleForm.subjectId" v-if="ruleForm.subjectClassId == '1'"
                                placeholder="请选择一级学科" clearable>
                                <el-option v-for=" item  in  skxkflList " :key="item.id" :label="item.label"
                                    :value="item.id" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="项目来源" prop="projectSourceId">
                            <el-select v-model="ruleForm.projectSourceId" clearable>
                                <el-option v-for=" item  in  projectSourceList.value " :key="item.id" :label="item.label"
                                    :value="item.id" />
                            </el-select>                                                  
                        </el-form-item>
                    </el-col>
                       <el-col :span="12">
                        <el-form-item label="论文链接地址" prop="url">
                               <el-input v-model="ruleForm.url"  placeholder="请输入论文链接地址" />
                        </el-form-item>
                    </el-col>
                </el-row>

            </div>
        </div>
        <!-- 详细信息 -->
        <div class="bg-white mt-[10px]">
            <BaseHead>详细信息</BaseHead>
            <div class="p-[10px]">

                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="发表范围" prop="publishRangeId">
                            <el-select v-model="ruleForm.publishRangeId" placeholder="请选择发表范围" clearable>
                                <el-option v-for="item in fbfwList" :key="item.code" :label="item.name"
                                    :value="item.code" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="学校署名">
                            <el-radio-group v-model="ruleForm.schoolSign">
                                <el-radio value="0" size="large">第一单位</el-radio>
                                <el-radio value="1" size="large">非第一单位</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="卷期页">
                            <el-input placeholder="请输入卷期页" v-model="ruleForm.juanQiYe" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="DOI">
                            <el-input placeholder="请输入DOI" v-model="ruleForm.doi" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="ISSN号">
                            <el-input placeholder="请输入ISSN号" v-model="ruleForm.issn" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="CN号">
                            <el-input placeholder="请输入CN号" v-model="ruleForm.claimId" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    
                    <el-col :span="12">
                        <el-form-item label="电子版附件" prop="fileIds">
                            <FileUpload :uploadUrl="uploadUrl" tip="附件大小不超过20M，上传论文全文电子版"  class="flex-1"
                           exceedLimitType="disabled"    accept=".doc,.docx,.pdf"  v-model="fileList" @change="fileChange">
                            </FileUpload>
                        </el-form-item>
                    </el-col>
                </el-row>

            </div>
        </div>
        <!-- 作者信息 -->
        <div class="bg-white mt-[10px]">
            <BaseHead>作者信息
                <template v-slot:Rslot>
                    <el-button @click="addHonor">添加</el-button>
                </template>
            </BaseHead>
            <div class="p-[10px]">
                <el-table :data="tableData" border style="width: 100%">
                    <el-table-column align="center" type="index" label="署名顺序" width="80" />
                    <el-table-column align="center" prop="date" label="作者类型">
                        <template #default="scope">
                            <el-select v-model="scope.row.authorType"
                                :disabled="scope.row.disable || (Cookies.get('role-key') == 'biz_kyry' && scope.$index == 0)"
                                @change="e => {
        selectAuthorType(e, scope.$index);
    }
        ">
                                <el-option v-for=" item  in  wcrTypelist " :key="item.code" :label="item.name"
                                    :value="item.code" />
                            </el-select>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="name" label="作者姓名">
                        <template #default="scope">
                            <el-select v-model="scope.row.authorName"
                                :disabled="scope.row.disable || (Cookies.get('role-key') == 'biz_kyry' && scope.$index == 0)"
                                @change="e => {
        selectAuthor(e, scope.$index, scope.row);
    }
        " v-if="scope.row.authorType != '3'" filterable remote reserve-keyword placeholder="请输入关键字检索"
                                :remote-method="remoteMethod" :loading="loading">
                                <el-option v-for=" item  in  options " :key="item.value" :label="item.label"
                                    :value="item.value" />
                            </el-select>
                            <!-- <el-autocomplete v-model="scope.row.authorName" v-else placeholder="请输入关键字检索"
                                value-key="label" :fetch-suggestions="querySearchAsync"
                                @select="e => { handleSelect(e, scope.$index) }" /> -->
                            <el-input v-model="scope.row.authorName" v-else />
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="address" label="学历">
                        <template #default="scope">
                            <el-select v-model="scope.row.eduLevelId">
                                <el-option v-for=" item  in  xlList " :key="item.code" :label="item.name"
                                    :value="item.code" />
                            </el-select>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="address" label="职称">
                        <template #default="scope">
                            <el-tree-select v-model="scope.row.titleId" node-key="id" :data="zcList"
                                :render-after-expand="false" :props="defaultProps" />
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="address" label="角色类型">
                        <template #default="scope">
                            <el-select v-model="scope.row.isTxAuthor">
                                <el-option v-for=" item  in  lwzzList " :key="item.code" :label="item.name"
                                    :value="item.code" />
                            </el-select>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="address" label="工作单位">
                        <template #default="scope">
                            <el-input v-model="scope.row.authorUnit" v-if="scope.row.authorType == '3'" />
                            <el-select v-model="scope.row.authorUnitId" :disabled="scope.row.authorType == '1'" @change="e => {
        changUnit(e, scope.$index);
    }" v-else placeholder=" 请选择所属单位" clearable>
                                <el-option v-for=" item in sydwList" :key="item.codeColumn" :label="item.valueColumn"
                                    :value="item.codeColumn" />
                            </el-select>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="address" label="贡献率（%）">
                        <template #default="scope">
                            <el-input placeholder="" v-model.number="scope.row.workRatio" @input="e => {
        handleInput1(e, scope.$index);
    }
        " type="number">
                            </el-input>
                        </template>
                    </el-table-column>
                    <el-table-column align="center" prop="address" label="操作">
                        <template #default="scope">

                            <el-link type="primary" :underline="false"
                                v-if="!scope.row.disable && !(Cookies.get('role-key') == 'biz_kyry' && scope.$index == 0)"
                                @click="
        delHonor(scope.$index)">删除</el-link>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
        </div>
    </el-form>
</template>

<script setup>
import BaseHead from "@/views/project/components/BaseHead.vue";
import { getPersonDetails } from "@/api/achievement/common.js"
import { getpaperAdd, getpaperUpdate, getsourceList, getmagazineSelect } from "@/api/achievement/kycg"
import { ElMessage, ElMessageBox } from "element-plus";
import FileUpload from "@/views/project/components/FileUpload.vue"
import useCategoryStore from "@/store/modules/category";
import Cookies from 'js-cookie'
import useCommonFetch from "@/hooks/useCommonFetch";
let projectSourceList = ref([]); //项目来源下拉数据
const categoryStore = useCategoryStore();
const {
    sllb1,
    sllb2,
} = storeToRefs(categoryStore); // 解构状态
const {
    getsllbE1,
    getsllbE2,
} = categoryStore; // 解构方法

const props = defineProps({
    xlList: Array,
    zcList: Array,
    zcgsdwList: Array,
    jbList: Array,
    xmlyList: Array,
    fbfwList: Array,
    kjxkflList: Array,
    skxkflList: Array,
    lwlx: Array,
    lbList: Array,
    lwzzList: Array,
    sydwList: Array,
})
const defaultProps = {
    children: 'children',
    label: 'label',
}

const isEdit = ref(false)
const tableData = reactive([
    {
        authorType: '1',
        eduLevelId: '',
        authorName: '',
        isTxAuthor: '',
        titleId: '',
        authorUnit: '',
        authorUnitId: '',
        workRatio: null,
        personId: '',   //userId
        orderId: 1,
        authorAccount: "",   //职工号
        sexId: '',
        subjectId: "",
        unitId: '',
        unitName: '',
    },
]);
const addHonor = () => {
    tableData.push({
        authorType: '1',
        eduLevelId: '',
        authorName: '',
        isTxAuthor: '',
        titleId: '',
        authorUnit: '',
        authorUnitId: '',
        workRatio: null,
        personId: '',   //userId
        orderId: tableData.length ? tableData[tableData.length - 1].orderId + 1 : 1,
        authorAccount: "",   //职工号
        sexId: '',
        subjectId: "",
        unitId: '',
        unitName: '',
    })
}

const delHonor = (index) => {
    tableData.splice(index, 1)
}
const selectAuthorType = (e, index) => {
    let type1 = tableData[index].authorType
    let orderId1 = tableData[index].orderId
    tableData[index] = {
        authorType: type1,
        eduLevelId: '',
        authorName: '',
        isTxAuthor: '',
        titleId: '',
        authorUnit: '',
        authorUnitId: '',
        workRatio: null,
        personId: '',   //userId
        orderId: orderId1,
        authorAccount: "",   //职工号
        sexId: '',
        subjectId: "",
        unitId: '',
        unitName: '',
    }
    if (e == '3') {
        tableData[index].personId = '3'
    }
}
const wcrTypelist = reactive([
    {
        code: '1',
        name: '教师'
    },
    {
        code: '2',
        name: '学生'
    },
    {
        code: '3',
        name: '校外'
    },
]);
const ruleForm = reactive({
    name: '',
    publishDate: '',
    magazineName: '',
    modeId: '1',
    paperLevelIdList: [],
    embodyTypeIdList: [],
    sciPartition: '',
    factor: '',
    unitId: '',
    subjectClassId: "",
    subjectId: "",
    projectSourceId: "",
    url:"",
    publishRangeId: "",
    juanQiYe: "",
    doi: "",
    issn: "",
    claimId: "",
    schoolSign: "0",
    meetingName: "",
    meetingAddress: "",
    fileIds:""

})
const rules = reactive({
    name: [
        { required: true, message: '请输入名称', trigger: 'blur' },
    ],
    meetingName: [
        { required: true, message: '请输入会议名称', trigger: 'blur' },
    ],
    meetingAddress: [
        { required: true, message: '请输入会议地址', trigger: 'blur' },
    ],
    magazineName: [
        { required: true, message: '请输入发表/刊物论文集', trigger: 'blur' },
    ],
    authorizeUnit: [
        { required: true, message: '请输入批准单位', trigger: 'blur' },
    ],
    modeId: [
        {
            required: true,
            message: '请选择论文类型',
            trigger: 'change',
        },
    ],
    paperLevelIdList: [
        {
            required: true,
            message: '请选择刊物级别',
            trigger: 'blur',
        },
    ],
    sciPartition: [
        {
            required: true,
            message: '请选择SCI论文分区',
            trigger: 'change',
        },
    ],
    unitId: [
        {
            required: true,
            message: '请选择所属单位',
            trigger: 'change',
        },
    ],
    publishDate: [
        {
            required: true,
            message: '请选择发表/出版时间',
            trigger: 'change',
        },
    ], subjectClassId: [
        {
            required: true,
            message: '请选择教育部统计归属',
            trigger: 'change',
        },
    ],
    subjectId: [
        {
            required: true,
            message: '请选择一级学科',
            trigger: 'change',
        },
    ],
    publishRangeId: [
        {
            required: true,
            message: '请选择发表范围',
            trigger: 'change',
        },
    ],
    fileIds: [
        {
            required: true,
            message: '请上传附件',
        },
    ],
    url: [
        {
            required: true,
            message: '请输入论文链接地址',
        },
    ],
})
const handleInput1 = (value, index) => {
    if (value !== null) { // 检查是否为null（非数字）或已经是数字且在范围内
        tableData[index].workRatio = Math.max(0, Math.min(100, value)); // 确保值在0到100之间
    } else {
        tableData[index].workRatio = null; // 重置为null，或者你可以设置为一个默认值，比如0或空字符串，取决于你的需求
    }
};

const querySearchAsync = (queryString, cb) => {
    console.log(queryString, 'queryString')
    if (queryString) {
        let pamrs = {
            name: queryString
        }
        getPersonDetails(pamrs).then(res => {
            console.log(res, 'res')
            if (res.code == 200) {
                let arr = res.data;
                arr.map(item => {
                    item.value = item.name;
                    item.label = item.name;
                })
                cb(arr);
            }
        })
    } else {
        cb([]);
    }

    // const results = queryString
    //   ? links.value.filter(createFilter(queryString))
    //   : links.value

    // clearTimeout(timeout)
    // timeout = setTimeout(() => {
    //   cb(results)
    // }, 3000 * Math.random())
}

const handleSelect = (item, index) => {
    console.log(item)
    tableData[index].personId = item.id
    tableData[index].authorAccount = item.account
    tableData[index].sexId = item.sexId
    tableData[index].subjectId = item.subjectId
    tableData[index].authorUnitId = item.unitId
    tableData[index].authorUnit = item.unitName
    tableData[index].eduLevelId = item.eduLevelId
    tableData[index].titleId = item.titleId
}
const changUnit = (value, index) => {
    console.log(value, 'unitvalue')
    if (item) {
        tableData[index].authorUnit = zcgsdwList.value.find(item => item.codeColumn == value).valueColumn
    }
}
const options = ref([])
const loading = ref(false)
const remoteMethod = (query) => {
    if (query) {
        loading.value = true
        let pamrs = {
            name: query
        }
        getPersonDetails(pamrs).then(res => {
            console.log(res, 'res')
            if (res.code == 200) {
                let arr = res.data;
                arr.map(item => {
                    item.value = item.name + ' ' + item.account + ' ' + item.unitName;
                    item.label = item.name + ' ' + item.account + ' ' + item.unitName;
                })
                options.value = arr
                loading.value = false
            }
        })
    } else {
        options.value = []
    }
}
// unit_id
const selectAuthor = (e, index, row) => {
    console.log(e, index, row)
    console.log(options.value.find(item => item.value == e))
    let userInfo = options.value.find(item => item.value == e)
    let cfuserInfo = tableData.find(item => item.personId == userInfo.id)
    if (cfuserInfo) {
        tableData[index].authorName = ''
        ElMessage({
            message: '此人已在列表中，请勿重复添加',
            type: 'error',
        })
        return;
    } else {
        tableData[index].authorName = userInfo.name
        tableData[index].personId = userInfo.id
        tableData[index].authorAccount = userInfo.account
        tableData[index].sexId = userInfo.sexId
        tableData[index].subjectId = userInfo.subjectId
        tableData[index].authorUnitId = userInfo.unitId
        tableData[index].authorUnit = userInfo.unitName
        tableData[index].eduLevelId = userInfo.eduLevelId
        tableData[index].titleId = userInfo.titleId
    }


}

const ruleFormRef = ref()
const emit = defineEmits(['closeDiglog', 'nextStepMet', 'endLoading', 'startLoading']);
const submitForm = async (i, j = '0', k) => {
    if (!ruleFormRef.value) return
    await ruleFormRef.value.validate((valid, fields) => {
        if (valid) {
            console.log('submit!')
            let params = {
                ...ruleForm
            }
            if (tableData.length == 0) {
                ElMessage({
                    message: '请添加至少一条完成人信息',
                    type: 'error',
                })
                return;
            } else if (tableData[0].authorName == '') {
                ElMessage({
                    message: '请添加至少一条完成人信息',
                    type: 'error',
                })
                return;
            } else {
                let ContributionRate = 0
                tableData.forEach(item => {
                    ContributionRate += item.workRatio
                })
                if (ContributionRate > 100) {
                    ElMessage({
                        message: '贡献率不能大于100',
                        type: 'error',
                    })
                    return;
                }
            }
            params.authorList = tableData
            params.submitType = i ? i : Cookies.get("role-key") == 'biz_kyry' ? '1' : '2'
            if (j == '1') {
                params.submitType = params.checkstatus
            }
            console.log(k, 'k')
            if (k) {
                params.checkstatus = k.checkstatus
                params.isAuditor = k.isAuditor
            }
            console.log(params, 'params')
            emit('startLoading', "")
            if (params.id) {
                getpaperUpdate(params).then((res) => {
                    if (res.code == 200) {
                        ElMessage({
                            message: res.msg,
                            type: 'success',
                        })
                        if (isEdit.value || k) {
                            emit('closeDiglog', "")
                        } else {
                            emit('nextStepMet', tableData, params.id)
                        }
                    } else {
                        ElMessage({
                            message: res.msg,
                            type: 'error',
                        })
                    }
                    emit('endLoading', "")
                })
            } else {
                getpaperAdd(params).then((res) => {
                    if (res.code == 200) {
                        ElMessage({
                            message: res.msg,
                            type: 'success',
                        })
                        ruleForm.id = res.data
                        emit('nextStepMet', tableData, res.data)
                    } else {
                        ElMessage({
                            message: res.msg,
                            type: 'error',
                        })
                    }
                    emit('endLoading', "")
                })
            }
        } else {
            console.log('error submit!', fields)
        }
    })
}
const changeSub = () => {
    ruleForm.subjectId = '';
     ruleForm.projectSourceId = '';
}
const uploadUrl = `/commonFile/uploadFile?modelName=medicineApply`;
const fileList = ref([]);

const getRuleForm = (i) => {
    console.log(i, 'info')
    // ruleForm = i
    if (i.authorList && i.authorList.length > 0) {
        console.log(tableData, 'tableData')
        tableData.length = 0; // 清空数组
        tableData.push(...i.authorList); // 添加新元素

    }
    for (const key in i) {
        ruleForm[key] = i[key];
    }
    if(i.fileIds){
        fileList.value=[{
            name:i.fileNames,
            id:i.fileIds,
        }]
    }
    // if (i.fileList && i.fileList.length > 0) {
    //     fileList.value = i.fileList.map((item) => {
    //         return {
    //             name: item.fileName,
    //             id: item.id,
    //         };
    //     });
    // }
    isEdit.value = true;
    console.log(ruleForm, 'ruleForm')
}

//上传的文件改变
const fileChange = () => {
    const ids = fileList.value.map((item) => {
        const id = item.response ? item.response.data : item.id;
        return id;
    });
    ruleForm.fileIds = ids.join(",");
};

const qklwList = ref([])
const hylwList = ref([])

watch(
    () => props.jbList,
    (newVal) => {
        qklwList.value = newVal.filter(item => item.paperModeId.includes('1'))
        hylwList.value = newVal.filter(item => item.paperModeId.includes('2'))

    },
    { immediate: true },
);

const qklwslList = ref([])
const hylwslList = ref([])
watch(
    () => props.lbList,
    (newVal) => {
        qklwslList.value = newVal.filter(item => item.paperModeId.includes('1'))
        hylwslList.value = newVal.filter(item => item.paperModeId.includes('2'))

    },
    { immediate: true },
);


const querySearch = async (queryString, cb) => {
    if (queryString) {
        let parms = {
            year: ruleForm.publishDate,
            name: queryString
        }
        let res = await getmagazineSelect(parms)
        let results = res.rows.map(item => {
            return {
                value: item,
            }
        }
        )

        cb(results)
    } else {
        cb([])
    }
}

const magazineNameRef = ref(null)
const publishDateRef = ref(null)
const focusMagazineName = () => {
    if (!ruleForm.publishDate) {
        magazineNameRef.value.blur()
        ElMessage({
            message: '请先选择发表/出版时间',
            type: 'error',
        })
        publishDateRef.value.focus()
    }
}

const getKyryInfo = (i) => {
    if (i && i.length > 0) {
        console.log(tableData, 'tableData')
        tableData.length = 0;
        tableData.push(...i);
        if (i[0].authorUnitId) {
            ruleForm.unitId = i[0].authorUnitId
        }
    }
}

//监听统计归属的值改变
watch(
  () => ruleForm.subjectClassId,
  (newVal) => {
    projectSourceList.value = useCommonFetch("项目来源", newVal);
  }
);


// 把数据暴露出去供父组件调用
defineExpose({
    submitForm,
    getRuleForm,
    getKyryInfo
})
// onMounted(() => {
//     if (!sllb1.value.length) {
//         getsllbE1();
//     }
//     if (!sllb2.value.length) {
//         getsllbE2();
//     }

// });
</script>

<style scoped lang="scss">
@import url("@/views/achievement/index.scss");
</style>
